package code148;

import java.util.PriorityQueue;

/**
 * @author 韩迪
 * @date 2022/03/21 20:59
 **/
public class Code148 {



      private class ListNode {
          int val;
          ListNode next;
          ListNode() {}
          ListNode(int val) { this.val = val; }
          ListNode(int val, ListNode next) { this.val = val; this.next = next; }
      }
    private class Solution {
        public ListNode sortList(ListNode head) {
            //运用优先级队列解
            PriorityQueue<ListNode> queue = new PriorityQueue<>((x,y)->x.val-y.val);
            while(head!=null){
              queue.offer(head);
              head = head.next;
            }
            ListNode ret = new ListNode();
            ListNode temp =  ret;
            while (!queue.isEmpty()){
                temp.next= queue.poll();
                temp=temp.next;
            }
            return ret.next;
        }
    }
}
